﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using Bll;

namespace 财会系.admin.WeekCalendar
{
    public partial class WeekAdmin : System.Web.UI.Page
    {
        BllPublic b = new BllPublic();
        ModelPublic m = new ModelPublic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Type"] != null)
                {
                    m.Type = "0";
                    m.UserType = Session["Type"].ToString();
                    UserType.Text = m.UserType;

                    ContentBind();
                }

            }
        }

        public void ContentBind()
        {
            m.NavId = "13";
            m.UserType = UserType.Text;
            m.Type = "0";

            GVWeek.DataSource = b.Notice_Week_Inquire_All(m);
            GVWeek.DataBind();
        }

        protected void GVWeek_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#777777'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
            }
        }

        protected void GVWeek_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GVWeek.PageIndex = e.NewPageIndex;

            if (search.Text == "Search...标题、作者")
            {
                ContentBind();
            }
            else
            {
                Retrieve();
            }
        }

        protected void lbtnSelectAll_Click(object sender, EventArgs e)
        {
            //全选
            for (var i = 0; i < GVWeek.Rows.Count; i++)
            {
                CheckBox chkSelect = (CheckBox)this.GVWeek.Rows[i].FindControl("chkSelect");
                chkSelect.Checked = true;
            }
        }
        protected void lbtnReverse_Click(object sender, EventArgs e)
        {
            //反选
            for (var i = 0; i < GVWeek.Rows.Count; i++)
            {
                CheckBox chkSelect = (CheckBox)this.GVWeek.Rows[i].FindControl("chkSelect");
                chkSelect.Checked = !chkSelect.Checked;
            }
        }
        protected void lbtnCancel_Click(object sender, EventArgs e)
        {
            //取消
            for (var i = 0; i < GVWeek.Rows.Count; i++)
            {
                CheckBox chkSelect = (CheckBox)this.GVWeek.Rows[i].FindControl("chkSelect");
                chkSelect.Checked = false;
            }
        }
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            int f = 0;
            int num = 0;

            for (var i = 0; i < GVWeek.Rows.Count; i++)
            {
                CheckBox chkSelect = (CheckBox)this.GVWeek.Rows[i].FindControl("chkSelect");
                if (chkSelect.Checked)
                {
                    num++;

                    m.Id = ((Label)GVWeek.Rows[i].FindControl("lblWeekId")).Text;
                    bool del = b.Notice_Week_Delete(m);
                    if (del)
                    {
                        f++;
                    }
                }
            }

            if (f > 0)
            {
                Response.Write("<script>alert('删除成功！\\n您，共选中" + num + "条记录\\n共删除" + f + "条记录')</script>");
                
            }
            else
            {
                Response.Write("<script>alert('删除失败！')</script>");
                
            }
            if (search.Text == "Search...标题、作者")
            {
                ContentBind();
            }
            else
            {
                Retrieve();
            }

        }

        protected void sumbit_Click(object sender, EventArgs e)
        {
            Retrieve();
        }

        private void Retrieve()
        {
            if (search.Text == "Search...标题、作者")
                m.Conditions = "";
            else
                m.Conditions = search.Text;

            m.NavId = "13";
            m.UserType = UserType.Text;
            m.Type = "0";

            GVWeek.DataSource = b.Notice_Week_Search_All(m);
            GVWeek.DataBind();
        }
    }
}